﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FTchina.Models;
using PWMIS.DataMap.Entity;
using FTchina.Library;
namespace FTchina.Logic
{
    /// <summary>
    ///UserGroupLogic 的摘要说明
    /// </summary>
    public class UserGroupLogic
    {
        public UserGroupLogic()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        /// <summary>
        /// 查看是否在菜单管理中使用
        /// </summary>
        /// <param name="GroupID"></param>
        /// <returns>true:在用</returns>
        public static Boolean IsInMenuUse(string GroupID)
        {
            bool flag = false;
            MenuList ul = new MenuList();
            OQL q = new OQL(ul);
            q.Select().Where().OrderBy(ul.Power, "desc");
            List<MenuList> list = EntityQuery<MenuList>.QueryList(q).ToList<MenuList>();
            foreach (MenuList ulist in list)
            {
                 
                if(StringHelper.ChkISinArray(GroupID,StringHelper.String2ArrayList(ulist.Power)))
                {                    
                    flag=true;
                    break;
                }
            }
            return flag;
        }
        /// <summary>
        /// 查看是否在用户管理中使用
        /// </summary>
        /// <param name="GroupID"></param>
        /// <returns>true:在用</returns>
        public static Boolean IsInUserListUse(string GroupID)
        {
            bool flag = false;
            Master ul = new Master();
            OQL q = new OQL(ul);
            q.Select().Where().OrderBy(ul.Usergroup, "desc");
            List<Master> list = EntityQuery<Master>.QueryList(q).ToList<Master>();
            foreach (Master ulist in list)
            {

                if (StringHelper.ChkISinArray(GroupID, StringHelper.String2ArrayList(ulist.Usergroup)))
                {
                    flag = true;
                    break;
                }
            }
            return flag;
        }

        /// <summary>
        /// 检查是否为系统项，系统项不允许删除
        /// </summary>
        /// <param name="ItemID"></param>
        /// <returns></returns>
        public static Boolean ChkIsSys(string ItemID)
        {
            
            UserGroup ug = new UserGroup();
            ug.Id = Convert.ToInt32(ItemID);
            EntityQuery<UserGroup> q = new EntityQuery<UserGroup>(ug);
            q.FillEntity(ug);
            return ug.IsSys == "1";
        }
    }
}